package com.mq.delay;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ytj
 * @date 2024/1/16
 */
@Configuration
public class Demo8Config {
    @Bean
    public Queue demo8Queue() {
        return QueueBuilder.durable(Demo8Message.QUEUE)
                .exclusive()
                .autoDelete()
                .ttl(10*1000)//队列中默认过期时间为10秒
                .deadLetterExchange(Demo8Message.EXCHANGE)
                .deadLetterRoutingKey(Demo8Message.DELAY_ROUTINGKEY)
                .build();
    }

    @Bean
    public Queue demo8DelayQueue(){
        return new Queue(Demo8Message.DELAY_QUEUE,true,false,false);
    }

    @Bean
    public DirectExchange demo8Exchange() {
        return new DirectExchange(Demo8Message.EXCHANGE, true, false);
    }

    @Bean
    public Binding demo8Binding() {
        return BindingBuilder.bind(demo8Queue()).to(demo8Exchange()).with(Demo8Message.ROUTINGKEY);
    }

    @Bean
    public Binding demo8DelayBinding(){
        return BindingBuilder.bind(demo8DelayQueue()).to(demo8Exchange()).with(Demo8Message.DELAY_ROUTINGKEY);
    }
}
